package threshold;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author wujiaming
 * @Description TODO
 * @Date 2023-03-01 20:28
 * @Version 1.0
 */
public class OneToZero {

    public int[][] oneToZero(int[][] nums){
        int[][] temps=new int[nums.length][nums[0].length];
        for (int i = 0; i <nums.length ; i++) {
            for (int j = 0; j <nums[i].length ; j++) {
                temps[i][j] = nums[i][j];
            }
        }
        for (int i = 0; i < temps.length; i++) {
            for (int j = 0; j <temps[0].length ; j++) {
                if(temps[i][j]==1){
                    //将第i行的元素都值为零
                    for (int k = 0; k <nums[i].length ; k++) {
                        nums[i][k]=0;
                    }
                    //将第j列值为零
                    for (int k = 0; k <nums.length ; k++) {
                        nums[k][j]=0;
                    }
                }
            }
        }
        return  nums;
    }

    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[][] nums = new int[m][n];
        for (int i = 0; i <m ; i++) {
            for (int j = 0; j <n ; j++) {
                nums[i][j] = sc.nextInt();
            }
        }
        OneToZero oneToZero = new OneToZero();
        System.out.println("原数组为");
        for (int i = 0; i <nums.length ; i++) {
            for (int j = 0; j <nums[i].length ; j++) {
                System.out.print(nums[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println();

        int[][] toNums = oneToZero.oneToZero(nums);

         System.out.println("转化后的数组为:");
        for (int i = 0; i <toNums.length ; i++) {
            for (int j = 0; j <toNums[i].length ; j++) {
                System.out.print(toNums[i][j]+" ");
            }
            System.out.println();
        }
    }
}
